/*
 * @Description: TB6612 驱动的定义
 * @Author: diyhome
 * @Gitee: https://gitee.com/jingjiangxueyuan_hmqs
 * @Date: 2019-10-04 16:44:35
 * @LastEditors: diyhome
 * @LastEditTime: 2019-10-14 15:14:16
 */
#include "Arduino.h"
#include "TB6612.h"

TB6612::TB6612(int Port[7])
{
    //初始化引脚,顺便赋值给私有变量
    for (int i = 0; i < 7; i++) {pinMode(Port[i], OUTPUT); SPort[i] = Port[i];}

    digitalWrite(SPort[3], 1);
}

void TB6612::CtrlTB6612(int pwm, int state_A, int state_B)
{
    int A,B;
    (state_A == 0) ? A = 1 : A =0;
    (state_B == 0) ? B = 1 : B = 0;
    digitalWrite(SPort[2], state_A);    digitalWrite(SPort[4], state_B);
    digitalWrite(SPort[1], A);    digitalWrite(SPort[5], B);

    analogWrite(SPort[0], pwm); analogWrite(SPort[6], pwm);
}